package com.lishe.lishe.lishe.module.mall.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.mall.bean.MallItemObject;
import com.lishe.lishe.lishe.module.mall.presenter.MallMainAdapterPresenter;

import java.util.List;

/**
 * Created by shino on 2017/11/6.
 * 商城首页分类栏
 */

public class MallClassifyAdapter extends RecyclerviewBaseAdapter {
    List<MallItemObject> mallItemObjects;
    Activity context;

    public MallClassifyAdapter(Activity context, List<MallItemObject> mallItemObjects) {
        this.mallItemObjects = mallItemObjects;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_classify, null);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder0, int position) {
        Holder holder = (Holder) holder0;
        final MallItemObject mallItemObject = mallItemObjects.get(position);
        holder.title.setText(mallItemObject.getName());
        ImageLoaderUtils.displayImage(context, mallItemObject.getImg_url(), holder.icon);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MallMainAdapterPresenter.classifyItemOnClick((Activity)context,mallItemObject);
            }
        });
    }

    @Override
    public int getItemCountMy() {
        return mallItemObjects == null ? 0 : mallItemObjects.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView title;
        ImageView icon;

        public Holder(View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.title);
            icon = itemView.findViewById(R.id.icon);
        }
    }
}
